package cn.xinfei.xdecision.common.utils.exception;

import cn.xinfei.xdecision.common.utils.exception.enums.ErrorCodeEnum;
import lombok.Getter;

/**
 * 自定义异常消息处理
 */
@Getter
public class ApiException extends RuntimeException {

    private static final long serialVersionUID = 1136843834946392402L;

    /**
     * 异常编码
     */
    public final String errCode;

    /**
     * 异常消息
     */
    public final String message;

    /**
     * data
     */
    public final Object data;

    public ApiException(Throwable e) {
        super(e);
        errCode = "";
        message = "";
        data = null;
    }

    public ApiException(String errCode, String message) {
        super(message);
        this.errCode = errCode;
        this.message = message;
        this.data = null;
    }

    public ApiException(ErrorCodeEnum errorCodeEnum) {
        super(errorCodeEnum.getMessage());
        this.errCode = errorCodeEnum.getCode();
        this.message = errorCodeEnum.getMessage();
        this.data = null;
    }

    public ApiException(String errCode, String message, Object data) {
        super(message);
        this.errCode = errCode;
        this.message = message;
        this.data = data;
    }

    public ApiException(String errCode, String message, Throwable e) {
        super(message, e);
        this.errCode = errCode;
        this.message = message;
        this.data = null;
    }

    public ApiException(String errCode, String message, Object data, Throwable e) {
        super(message, e);
        this.errCode = errCode;
        this.message = message;
        this.data = data;
    }

}
